home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Programming / Programming Tools / Turbo Pascal / Utilities / QNAPAS.TXT < prev   
Encoding:
Text File  |  1987-06-16  |  8.8 KB  |  248 lines  |  [TEXT/ttxt]

  1.  
  2.             TURBO PASCAL FOR THE MACINTOSH
  3.              Common Questions and Answers:
  4.  
  5. Q: Do I need Turbo to run programs I developed using Turbo? 
  6.  
  7. A: No, you can create a "stand-alone" (double-clickable)
  8. application  by  selecting  the  Compile  To  Disk  item from the
  9. Compile menu. 
  10.  
  11.  
  12. Q:What are the code and data limits for a Turbo Pascal program?
  13.  
  14. A:The Macintosh limits the code size of a program to 32K bytes. 
  15. You can overcome this limitation by segmenting your program. 
  16. This means you can have several 32K segments and you are the size
  17. of your program is only by disk space.  For more information on
  18. segmenting see the Large Programs and Segmentation in chapter 9
  19. and the Units and Large Programs section in chapter 8.
  20.  
  21. The Macintosh limits a program to 32K bytes of global data.  To
  22. overcome this limitation you can use pointers as in the following
  23. sample: 
  24. program SaveSpace;
  25. type
  26.   BigArray = array[1..$8000] of integer;
  27.    { if we declared a variable of this type it would occupy 16K }
  28.                      {  bytes.  Half of our global data space!! }
  29. var
  30.   SpaceSaver : ^BigArray;
  31.   i : integer;
  32. begin
  33.   New(SpaceSaver);   { allocate space for array off of the heap }
  34.   for i := to $8000 do
  35.     SpaceSaver^[i] := i; { index element by derefencing pointer }
  36. end.
  37.  
  38.  
  39. Q: How to a raise a number to a power?
  40.  
  41. A: Include the following function in your program:
  42.  
  43.   function Raise(x, y : real) : real;
  44.   begin
  45.     Raise := exp(y * ln(x));
  46.   end; { Raise }
  47.  
  48.  
  49. Q: How do I take the log base 10 of a number?
  50.  
  51. A: Include the following function in your program:
  52.    function Log(r : real) : real;
  53.    begin
  54.      Log := ln(r) / ln(10);
  55.    end;  
  56.  
  57.  
  58. Q: I am trying to call one of the Macintosh Toolbox routines
  59. which takes a parameter of type PTR and I get a compiler error 44
  60. (type mismatch) when I pass it a StringPtr.  How can I get this
  61. to compile?
  62.  
  63. A: Because of Pascal's strong typing rules, you can't directly
  64. assign a value of type PTR for example to some other pointer
  65. type.  Instead, you have to coerce the pointer from one type to
  66. another with variable type casts.  For an example please refer to
  67. the Variable-Type-Casts section at the end of chapter 19 in the
  68. Turbo Refernce manual.
  69.  
  70.  
  71. Q: I am writing a program that uses a "Macintosh Interface" but
  72. when the program starts up a window flashes up on the screen and
  73. then disappears.  How do I get rid of this window altogether?
  74.  
  75. A: You are seeing is Turbo's PasConsole window which makes it
  76. easy to set up text book programs.  To eliminate PasConsole set
  77. the {$U-} directive after your program statement.
  78.  
  79. Warning: Pasconsole initialize various Toolbox managers for you
  80. so if you set {$U-} you must explicitily initialize these
  81. managers.  Please refer to the Initialization section in chapter
  82. 9 of the Turbo Pascal Reference Manual.
  83.  
  84.  
  85. Q: I am trying to write a program using QuickDraw but its not
  86. working.  Nothing seems to be getting initialized as the
  87. documentation in Inside Macintosh indicates.  What is going
  88. wrong?
  89.  
  90. A: If your program does not have the {$U-} directive, the
  91. PasConsole unit will automatically used in your program. 
  92. Pasconsole defines and initializes its own set of QuickDraw
  93. global variables to support the console window.
  94.  
  95. If your program uses both Pasconsole and QuickDraw, the QuickDraw
  96. Unit's own set of global variables need to be initialized by
  97. making the call InitGraf(@thePort).  Before doing this however
  98. you need to save the pointer to the PasConsole window or its
  99. value will be wiped out InitGraf call as illustrated below. 
  100. Include the following procedure in your program and call it once
  101. at the very beginning of your program. 
  102.  
  103. procedure SetUpQuickDraw;
  104. var
  105.   TurboPort : GrafPtr;
  106. begin
  107.   GetPort(TurboPort);  { Save the PasConsole window pointer }
  108.   InitGraf(@thePort);
  109.   SetPort(TurboPort); { Restore the PasConsole window pointer }
  110. end;
  111.  
  112.  
  113. Q: How do I generate random numbers with Turbo for the Mac?  I
  114. tried using QuickDraw's random number generator but I each time 
  115. the program runs it generates the same sequence of numbers even
  116. though I change the value of RandSeed (the seed value used by the
  117. genearator).  What am I doing wrong?
  118.  
  119. A: RandSeed is a QuickDraw global variable so you need to
  120. initialize this variable with the SetUpQuickDraw procedure listed
  121. above.  Below is a sample program that uses the system clock to
  122. ensure that the program generates a different sequence of numbers
  123. each time:
  124.  
  125. program RandomTest;
  126. uses MemTypes, QuickDraw, OSIntf, ToolIntf;
  127.  
  128. var 
  129.   i : integer;
  130. begin
  131.   SetUpQuickDraw; { use the procedure listed above }
  132.   RandSeed := TickCount; { Set the seed to the time }
  133.   for i := 1 to 20 do
  134.     Writeln(abs(Random) mod i);
  135.   Readln;
  136. end.
  137.  
  138.  
  139. Q: How do I output text from my program to the printer?
  140. A: You must include the PasPrinter unit and Write to the Printer
  141. logical device as shown below:
  142.  
  143. program PrintTest;
  144. uses PasPrinter;
  145.  
  146. begin
  147.   Writeln(Printer, 'Send this to the printer');
  148.   Close(Printer);
  149. end.
  150.  
  151. Note: On LaserWriter printers you MUST close the Printer logical
  152. device to get output.
  153.  
  154.  
  155. Q: How do I do a screen dump to the printer?  I want to print out
  156. QuickDraw graphics as well as Turbo's Turtle graphics?
  157.  
  158. A: The following program demonstrates the Macintosh calls to
  159. print the top folder on the screen and/or the whole screen:
  160.  
  161. program ScreenDump;
  162. uses MemTypes, QuickDraw, OSIntf, ToolIntf, MacPrint;
  163.  
  164. procedure HardCopy(TopWindowOnly : boolean);
  165. begin
  166.   PrDrvOpen;
  167.   if TopWindowOnly then 
  168.     PrtCall(iPrEvtCtl, LprEvtTop, 0, LScreenBits)
  169.   else
  170.     PrtCall(iPrEvtCtl, LprEvtAll, 0, LScreenBits);
  171.   PrDrvrClose;
  172. end; { HardCopy }
  173.  
  174. begin
  175.   HardCopy(true);  { print Turbo's PasConsole window }
  176. end.
  177.  
  178.  
  179. Q: How do I find get more documentation on the procedures and
  180. functions listed in the Macintosh Interfaces Units listed in
  181. Appendix D of the Turbo Pascal Reference Manual?
  182.  
  183. A: Apple Computer's official documentation, INSIDE MACINTOSH, is
  184. the most complete documentation on the Macintosh and its
  185. Toolboxes.
  186.  
  187.  
  188. Q: The Turbo Reference Manual it indicates you can shift text
  189. left and right using the (clover)[ and (clover)] keys.  I was
  190. unable to shit the text in my program.  Also these commands are
  191. not highlighted on the Edit menu.  What is wrong?
  192.  
  193. A: The text you highlight to be shifted must be made up of
  194. complete lines of text.  To mark a complete line move the mouse
  195. to the leftmost column on the screen and select the text using
  196. the click and drag method moving straight down the left side. 
  197. You should see the lines highlighted all the way across the
  198. screen.  You can then shift the (rectangular) block.
  199.  
  200.  
  201. Q: Is there any way to stop a Turbo program short of hitting the
  202. Reset button and restarting the machine which is very time consuming?
  203.  
  204. A: The following procedure sets up your system to allow you to
  205. break out of a Turbo Pascal program without rebooting.  On the
  206. SAMPLES AND UTILITIES diskette in the MISCELLANEOUS folder there
  207. is a file calles MACSBUG.  If you put this file in your System
  208. Folder and restart your system, the MACSBUG debugger will
  209. automatically be loaded into memory.  Now, whenever you need to
  210. break out of a Turbo program press the interrupt switch (the
  211. switch behind the reset switch on the left side of your
  212. Macintosh, assuming you have installed the switches).  This will
  213. put you in the MacsBug debugger and you will see a ">" prompt. 
  214. At this prompt type ES and you will be returned to the Turbo
  215. Environment.
  216.  
  217.  
  218. Q: When I run my Turbo program it bombs bringing up a Macintosh
  219. bomb box with Error 2.  After hitting the Resume Error it goes
  220. into the Turbo brings up an error message saying TARGET ADDRESS
  221. FOUND IN UNIT placing the cursor at the end of my source file. 
  222. What is happening?
  223.  
  224. A: A system error 2 is an addressing error because some Macintosh
  225. Toolbox routine is being passed an invalid pointer or handle. 
  226. Since the error is happening in one of these pre-compiled units
  227. Turbo cannot take to the source line of the error.  Make sure
  228. that your program checks all error codes returned from Toolbox
  229. routines and make sure no errors have occurred before proceeding. 
  230. Also refer to the chapter DEBUGGING YOUR TURBO PASCAL PROGRAM in
  231. the Turbo Pascal Reference Manual.
  232.  
  233.  
  234. Q: I am trying to port over some Turbo Pascal programs from the
  235. IBM PC to Turbo Pascal for the Macintosh and I am getting
  236. compiler errors.  Why isn't Turbo for the Mac fully compatible?
  237.  
  238. A: Serious Pascal developers on the Macintosh have adopted the
  239. Lisa Pascal standard.  So it was necessary that Turbo Pascal
  240. follows these standards.  We have tried to also maintain close
  241. compatibility with other implementations of Turbo Pascal.  When
  242. these standards conflict it was necessary that we adopt the Lisa
  243. Pascal standard.  For closer compatibility with the IBM PC
  244. version of Turbo Pascal we have implemented a compatibility unit
  245. that you can include in your programs.  This unit is in a file
  246. called Compat.inc in data library 5 of the Borland Programmers
  247. Forum.
  248.